using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WLYT.Application.Interfaces;
using WLYT.Domain.Model;
using WLYT.Repository;

namespace WLYT.Application.Services
{
    public class InventoryLogService : BaseService<InventoryLog>, IInventoryLogService
    {
        public ISqlSugarRepository<InventoryLog> InventoryLogRepository;
        public InventoryLogService(ISqlSugarRepository<InventoryLog> inventoryLogRepository) : base(inventoryLogRepository)
        {
            InventoryLogRepository = inventoryLogRepository;
        }

        public async Task<Tuple<IList<InventoryLog>, int>> GetModelsByPageAsync(string itemCode, string labelId, string itemDesc, string docNum, string location, string type, int pageSize, int pageIndex)
        {
            Expressionable<InventoryLog> exp = Expressionable.Create<InventoryLog>();
            exp.AndIF(!string.IsNullOrEmpty(itemCode), p => p.ItemCode.Contains(itemCode));
            exp.AndIF(!string.IsNullOrEmpty(labelId), p => p.LabelId.Contains(labelId));
            exp.AndIF(!string.IsNullOrEmpty(itemDesc), p => p.ItemName.Contains(itemDesc));
            exp.AndIF(!string.IsNullOrEmpty(docNum), p => p.DocNum.Contains(docNum));
            exp.AndIF(!string.IsNullOrEmpty(location), p => p.Location.Contains(location));
            exp.AndIF(!string.IsNullOrEmpty(location), p => p.Type == type);
            return await GetPageListAsync(exp, pageSize, pageIndex, p => p.Id);
        }
    }
}